# -*- coding: UTF-8 -*-

import time
from datetime import datetime

YMD = '%Y%m%d'
YMD_ = '%Y-%m-%d'
YMDHMS_ = '%Y-%m-%d-%H_%M_%S'
YMDHMS = "%Y-%m-%d %H:%M:%S"
YMDHMS__ = '%Y-%m-%d-%H-%M-%S'


# 获取当前时间： 秒
def get_second():
    return str(time.time()).split('.')[0]


# 获取当前时间： 毫秒
def get_millisecond():
    return str(int(round(time.time()*1000, 0)))


# 获取当前日期时间,需指定时间格式
def get_datetime(format):
    return time.strftime(format, time.localtime(time.time()))


# 时间转化时间戳
def get_dateToSecond(date, format):
    return str(time.mktime(time.strptime(date, format))).split('.')[0]


def get_secondToDate(timeStamp, format):
    timeStamp = int(timeStamp)
    timeArray = time.localtime(timeStamp)
    otherStyleTime = time.strftime(format, timeArray)
    return otherStyleTime


# 日期 间隔天数
def dateNum(day1, day2):
    time_array1 = time.strptime(day1, YMD_)
    timestamp_day1 = int(time.mktime(time_array1))
    time_array2 = time.strptime(day2, YMD_)
    timestamp_day2 = int(time.mktime(time_array2))
    result = (timestamp_day2 - timestamp_day1) // 60 // 60 // 24
    return int(result)


# 同一天 时间 间隔
def time_interval(time1, time2):
    time_1_struct = datetime.strptime(time1, YMDHMS)
    time_2_struct = datetime.strptime(time2, YMDHMS)
    seconds = (time_2_struct - time_1_struct).seconds
    return seconds


# 获取当前时间年月日格式
def get_time_ymd():
    return time.strftime(YMD_, time.localtime(time.time()))
